import React from "react";

class Calc extends React.Component{
    constructor(props){
        super(props)
        this.state={value:1}
    }

    add=()=>{
        this.setState({value:this.state.value+1})
    }
    
    reduce=()=>{
        this.setState({value:this.state.value-1})
    }

    alter(){
        alert("点击了绑定")
    }

    //渲染
    render(){
        return (
           <div>
                <button onClick={this.add}>加1</button>
                <span>值是：{this.state.value}</span>
                <button onClick={this.reduce}>减一</button>
                <button onClick={this.alter.bind(this)}>绑定</button>
           </div>
        )
    }
}

export default Calc